package com.sy.controller.inventory;

import com.sy.bean.inventory.Damage;
import com.sy.bean.inventory.DamageQuery;
import com.sy.common.bean.PageBean;
import com.sy.common.bean.ResultBean;
import com.sy.common.controller.BaseController;
import com.sy.common.utils.BeanOfMap;
import com.sy.service.inventory.DamageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "报损单")
@RequestMapping("/api/Damage")
public class DamageController extends BaseController {


    @Autowired
    DamageService damageService;

    @PostMapping("/selectDamage")
    @ApiOperation(value = "查询报损单列表")
    public ResultBean selectDamage(@RequestBody DamageQuery damageQuery) {
        PageBean<Damage> pageBean = damageService.query(BeanOfMap.bom(damageQuery));
        return success("查询成功", pageBean);
    }

    @GetMapping("/examineById")
    @ApiOperation(value = "审核报损单")
    public ResultBean examineById(String reviewers,int id,int type) {
        int rs = damageService.examineById(reviewers, id, type);
        if (rs > 0) {
            return success("审核成功");
        } else {
            return fail("审核失败");
        }
    }

    @GetMapping("/queryById")
    @ApiOperation(value = "根据id查询报损单明细")
    public ResultBean queryById(int id) {
        Damage damage = damageService.queryById(id);
        return success("查询成功", damage);
    }


    @PostMapping("/insertDamage")
    @ApiOperation(value = "添加报损单")
    public ResultBean insertDamage(@RequestBody Damage damage) {
        int rs = damageService.insertDamage(damage);
        if (rs > 0) {
            return success("添加成功");
        } else {
            return fail("添加失败");
        }
    }



}
